package internal;

import java.sql.*;



public class SQL_Server_Adapter {
	
	/**
	 * @param args
	 * @throws SQLException 
	 */

	public static void main(String[] args) throws SQLException {
		
		//Initialize Variables
		Connection conn = null; 
		Statement stmt; 
		PreparedStatement pstm; 
		ResultSet rs = null;
		
		//Initalize Connection Configs
		 String port = "3305";
		 String host_addr = "127.0.0.1";
		 String schema_name = "DbMysql11";
		 String username = "DbMysql11";
		 String password= "DbMysql11";
		
		//TEST
		String query = "select * from countries";
		


		
		//Initialize Connection
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}

		//Connect To Scheme
		try {
			conn = DriverManager.getConnection("jdbc:mysql://" + host_addr + 
					":" + port +"/" + schema_name,
					username, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}
		
		

		stmt = conn.createStatement();
		

		
		
		//Using Regular Query
		rs = stmt.executeQuery(query);
		
		/*
		//Using Prepared Statement
		pstm = conn.prepareStatement("SELECT first_name FROM actor WHERE last_name = ? ");
		pstm.setString(1, "POSEY");
		pstm.addBatch();
		rs = pstm.executeQuery();
	*/
		

		
		while(rs.next() == true)
			System.out.println(rs.getString("country_name"));
		
		//Closing Connections
		conn.close();
		stmt.close();
	}
	
	

}
